<?php
    require '../tools.func.php';
    require '../db.func.php';
    require 'head.php';
    $prefix=getprefix();
    // $sql="SELECT  a.id,a.price,a.quantity,b.username,a.created_at FROM {$prefix}cart as a
    //     LEFT JOIN  {$prefix}user as b 
    //     on a.uid=b.id 
    //     ORDER BY a.created_at DESC";
    // 第一种方式用数据库语言
     $sql="SELECT  id,price,quantity,uid,created_at FROM {$prefix}cart 
        ORDER BY created_at DESC";
    $res=query($sql);
    $array=[];
    foreach ($res as $k) {
          $id=$k['uid'];
          $sql="SELECT username FROM {$prefix}user  WHERE id='{$id}'";
          $res1=queryone($sql);
  
          $k['uid']=$res1['username'];
          $array[]=$k;

    }
?>
          <div class="row">
            <div class="col-md-12">
              <div class="card">
                <div class="card-header card-header-primary">
                  <div class="row">
                    <div class="col-12">
                      <h4 class="card-title ">所有购物车</h4>
                      <p class="card-category"> 所有购物车列表</p>
                    </div>
                  </div>

                </div>
                <div class="card-body">
                  <div class="table-responsive">
                    <table class="table table-hover">
                      <thead class=" text-primary">
                      <th>
                        ID
                      </th>
                      <th>
                        购物车用户
                      </th>
                      <th>
                        商品总量
                      </th>
                      <th>
                        购物车总价
                      </th>
                      <th>
                        添加时间
                      </th>
                      <th>
                        编辑
                      </th>
                      </thead>
                      <tbody>
                      <?php  foreach ($array as $r):
                        
                       ?>
                      <tr>
                        <td>
                          <?php echo $r['id']; ?>
                        </td>
                        <td>
                          <!-- <?php echo $r['username']; ?> -->
                          <?php echo $r['uid']; ?>
                        </td>
                        <td>
                          <?php echo $r['quantity']; ?>
                        </td>
                        <td>
                          <?php echo $r['price']; ?>
                        </td>
                        <td>
                          <?php echo $r['created_at']; ?>
                        </td>
                        <td>
                          <a href="">删除</a>
                        </td>
                      </tr>
                    <?php endforeach; ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
      <?php  require 'foot.php'; ?>